using UnityEngine;
using UnityEngine.UI;

namespace Lean.Localization
{
	[ExecuteInEditMode]
	[DisallowMultipleComponent]
	[RequireComponent(typeof(Text))]
	public class LeanLocalizedTextFont : LeanLocalizedBehaviour
	{
		[Tooltip("If PhraseName couldn't be found, this font will be used")]
		public Font FallbackFont;

		public override void UpdateTranslation(LeanTranslation translation)
		{
			Text component = GetComponent<Text>();
			if (translation != null)
			{
				component.font = (translation.Object as Font);
			}
			else
			{
				component.font = FallbackFont;
			}
		}

		protected virtual void Awake()
		{
			if (FallbackFont == null)
			{
				Text component = GetComponent<Text>();
				FallbackFont = component.font;
			}
		}
	}
}
